home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / gold / valMethods.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  18.9 KB  |  741 lines

  1. /*
  2.  * The original copyright owners of the accompanying source code files have
  3.  * agreed to place such code into the public domain.  Accordingly, anyone
  4.  * who receives or obtains a copy of such source code is freely entitled to
  5.  * reproduce, use and otherwise exploit such code (including the right to
  6.  * make derivative works), at his/her own risk and expense, without any
  7.  * obligation or liability to the original copyright owners.
  8.  *
  9.  * We would appreciate (but do not require) that the following message be
  10.  * included in any derivative works:
  11.  *
  12.  * "Portions of this program were developed by Peter Broadwell, Rob Myers
  13.  * and Robin Schaufler while working in Silicon Valley."
  14.  *
  15.  * The accompanying source code files and related documentation materials
  16.  * are distributed on an "AS IS" basis, without any warranties or
  17.  * guarantees of any kind.  All implied warranties, including the implied
  18.  * warranties of merchantability and of fitness for any particular purpose,
  19.  * are expressly disclaimed.
  20.  */
  21. #include "gl.h"
  22. #include "geom.h"
  23. #include "class.h"
  24. #include "selectors.h"
  25. #include "classIds.h"
  26. #include "mbox.h"
  27. #include "individual.h"
  28. #include "colors.h"
  29. #include "camera.h"
  30. #include "panel.h"
  31. #include "valuator.h"
  32. #include "pick.h"
  33.  
  34. extern inst *clone();
  35.  
  36. extern valuator  valTemplate;
  37. extern valuatorf valfTemplate;
  38. extern valdelta  valDeltaTemplate;
  39. extern valdeltaf valDeltafTemplate;
  40. extern valmesg   valMesgTemplate;
  41. extern valmesgf  valMesgfTemplate;
  42. extern valhue    valHueTemplate;
  43. extern valval    valValTemplate;
  44.  
  45.     /*
  46.      *  initialize a valuator
  47.      */
  48.      panel *
  49. makeValuator(list, dad, f, ScrArea, clampIn, WorldArea, xVal, yVal, pObj, tObj)
  50.     register panel *list, *dad;
  51.     int f;
  52.     register rectangle  *ScrArea;
  53.     register point2d  *clampIn;
  54.     register rectangle *WorldArea;
  55.     int *xVal, *yVal;
  56.     Object pObj, tObj;
  57. {
  58.     register valuator *aValuator;
  59.  
  60.     if ((aValuator = (valuator *)clone(&valTemplate)) == NULL)
  61.     return list;
  62.     
  63.     aValuator->base.next = list;
  64.     aValuator->base.kids = NULL;
  65.     aValuator->base.dad  = dad;
  66.     aValuator->base.area = *ScrArea;
  67.     aValuator->base.painter = pObj;
  68.  
  69.     aValuator->flags   = f;
  70.     setClamp(&aValuator->clamp, ScrArea, clampIn);
  71.     aValuator->world   = *WorldArea;
  72.     aValuator->xVal    = xVal;
  73.     aValuator->yVal    = yVal;
  74.     aValuator->tracker = tObj;
  75.  
  76.     return (panel *)aValuator;
  77. }
  78.  
  79.  
  80.     /*
  81.      *  initialize a floating point valuator
  82.      */
  83.      panel *
  84. makeValuatorf(list, dad, f, ScrArea, clampIn, WorldArea, xVal, yVal, pObj, tObj)
  85.     register panel *list, *dad;
  86.     int f;
  87.     register rectangle  *ScrArea;
  88.     register point2d *clampIn;
  89.     register rectanglef *WorldArea;
  90.     Coord *xVal, *yVal;
  91.     Object pObj, tObj;
  92. {
  93.     register valuatorf *aValuator;
  94.  
  95.     if ((aValuator = (valuatorf *)clone(&valfTemplate)) == NULL)
  96.     return list;
  97.     
  98.     aValuator->base.next = list;
  99.     aValuator->base.kids = NULL;
  100.     aValuator->base.dad  = dad;
  101.     aValuator->base.area = *ScrArea;
  102.     aValuator->base.painter = pObj;
  103.  
  104.     aValuator->flags   = f;
  105.     setClamp(&aValuator->clamp, ScrArea, clampIn);
  106.     aValuator->world   = *WorldArea;
  107.     aValuator->xVal    = xVal;
  108.     aValuator->yVal    = yVal;
  109.     aValuator->tracker = tObj;
  110.  
  111.     return (panel *)aValuator;
  112. }
  113.  
  114.     /*
  115.      *  initialize a delta valuator
  116.      */
  117.      panel *
  118. makeValDelta(list, dad, f, ScrArea, clampIn, WorldArea, xVal, yVal, Limits,pObj)
  119.     register panel *list, *dad;
  120.     int f;
  121.     register rectangle  *ScrArea;
  122.     register point2d *clampIn;
  123.     register rectangle *WorldArea;
  124.     int *xVal, *yVal;
  125.     register rectangle *Limits;
  126.     Object pObj;
  127. {
  128.     register valdelta *aValuator;
  129.  
  130.     if ((aValuator = (valdelta *)clone(&valDeltaTemplate)) == NULL)
  131.     return list;
  132.     
  133.     aValuator->base.next = list;
  134.     aValuator->base.kids = NULL;
  135.     aValuator->base.dad  = dad;
  136.     aValuator->base.area = *ScrArea;
  137.     aValuator->base.painter = pObj;
  138.  
  139.     aValuator->flags   = f;
  140.     setClamp(&aValuator->clamp, ScrArea, clampIn);
  141.     aValuator->world   = *WorldArea;
  142.     aValuator->xVal    = xVal;
  143.     aValuator->yVal    = yVal;
  144.     aValuator->limits  = *Limits;
  145.  
  146.     return (panel *)aValuator;
  147. }
  148.  
  149.     /*
  150.      *  initialize a floating point delta valuator
  151.      */
  152.      panel *
  153. makeValDeltaf(list, dad, f, ScrArea, clampIn, WorldArea, xVal, yVal,Limits,pObj)
  154.     register panel *list, *dad;
  155.     int f;
  156.     register rectangle  *ScrArea;
  157.     register point2d *clampIn;
  158.     register rectanglef *WorldArea;
  159.     Coord *xVal, *yVal;
  160.     register rectanglef *Limits;
  161.     Object pObj;
  162. {
  163.     register valdeltaf *aValuator;
  164.  
  165.     if ((aValuator = (valdeltaf *)clone(&valDeltafTemplate)) == NULL)
  166.     return list;
  167.     
  168.     aValuator->base.next = list;
  169.     aValuator->base.kids = NULL;
  170.     aValuator->base.dad  = dad;
  171.     aValuator->base.area = *ScrArea;
  172.     aValuator->base.painter = pObj;
  173.  
  174.     aValuator->flags   = f;
  175.     setClamp(&aValuator->clamp, ScrArea, clampIn);
  176.     aValuator->world   = *WorldArea;
  177.     aValuator->xVal    = xVal;
  178.     aValuator->yVal    = yVal;
  179.     aValuator->limits  = *Limits;
  180.  
  181.     return (panel *)aValuator;
  182. }
  183.  
  184.  
  185.     /*
  186.      *  initialize a message-sending valuator
  187.      */
  188.      panel *
  189. makeValMesg(list, dad, f, ScrArea, clampIn, WorldArea, x,y, rec,sel,r,pObj,tObj)
  190.     register panel *list, *dad;
  191.     int f;
  192.     register rectangle  *ScrArea;
  193.     register point2d *clampIn;
  194.     register rectangle *WorldArea;
  195.     int x, y;
  196.     inst *rec;
  197.     int sel;
  198.     int r;
  199.     Object pObj, tObj;
  200. {
  201.     register valmesg *aValuator;
  202.  
  203.     if ((aValuator = (valmesg *)clone(&valMesgTemplate)) == NULL)
  204.     return list;
  205.     
  206.     aValuator->base.next = list;
  207.     aValuator->base.kids = NULL;
  208.     aValuator->base.dad  = dad;
  209.     aValuator->base.area = *ScrArea;
  210.     aValuator->base.painter = pObj;
  211.  
  212.     aValuator->flags   = f;
  213.     setClamp(&aValuator->clamp, ScrArea, clampIn);
  214.     aValuator->world   = *WorldArea;
  215.     aValuator->val.x   = x;
  216.     aValuator->val.y   = y;
  217.     aValuator->receiver= rec;
  218.     aValuator->selector= sel;
  219.     aValuator->reset   = r;
  220.     aValuator->tracker = tObj;
  221.  
  222.     return (panel *)aValuator;
  223. }
  224.  
  225.     /*
  226.      *  initialize a floating point message-sending valuator
  227.      */
  228.      panel *
  229. makeValMesgf(list, dad, f, ScrArea, clampIn, WorldArea, x,y,rec,sel,r,pObj,tObj)
  230.     register panel *list, *dad;
  231.     int f;
  232.     register rectangle  *ScrArea;
  233.     register point2d *clampIn;
  234.     register rectanglef *WorldArea;
  235.     Coord x, y;
  236.     inst *rec;
  237.     int sel;
  238.     int r;
  239.     Object pObj, tObj;
  240. {
  241.     register valmesgf *aValuator;
  242.  
  243.     if ((aValuator = (valmesgf *)clone(&valMesgfTemplate)) == NULL)
  244.     return list;
  245.     
  246.     aValuator->base.next = list;
  247.     aValuator->base.kids = NULL;
  248.     aValuator->base.dad  = dad;
  249.     aValuator->base.area = *ScrArea;
  250.     aValuator->base.painter = pObj;
  251.  
  252.     aValuator->flags   = f;
  253.     setClamp(&aValuator->clamp, ScrArea, clampIn);
  254.     aValuator->world   = *WorldArea;
  255.     aValuator->val.x   = x;
  256.     aValuator->val.y   = y;
  257.     aValuator->receiver= rec;
  258.     aValuator->selector= sel;
  259.     aValuator->reset   = r;
  260.     aValuator->tracker = tObj;
  261.  
  262.     return (panel *)aValuator;
  263. }
  264.  
  265.     panel *
  266. makeValHue(list, dad, f, ScrArea, clampIn, color, hueId, showId)
  267.     register panel *list, *dad;
  268.     int f;
  269.     register rectangle *ScrArea;
  270.     register point2d *clampIn;
  271.     int color;
  272.     Object hueId, showId;
  273. {
  274.     register valhue *aValuator;
  275.  
  276.     if ((aValuator = (valhue *)clone(&valHueTemplate)) == NULL)
  277.     return list;
  278.     
  279.     aValuator->base.next = list;
  280.     aValuator->base.kids = NULL;
  281.     aValuator->base.dad  = dad;
  282.     aValuator->base.area = *ScrArea;
  283.     aValuator->base.painter = hueId;
  284.  
  285.     aValuator->flags   = f;
  286.     setClamp(&aValuator->clamp, ScrArea, clampIn);
  287.     aValuator->world.orig.x = 0;
  288.     aValuator->world.orig.y = 0;
  289.     aValuator->world.extent.x = MAXHUE;
  290.     aValuator->world.extent.y = MAXSAT;
  291.     aValuator->display = showId;
  292.  
  293.     return (panel *)aValuator;
  294. }
  295.  
  296.     panel *
  297. makeValVal(list, dad, f, ScrArea, clampIn, color, valId, showId)
  298.     register panel *list, *dad;
  299.     int f;
  300.     register rectangle *ScrArea;
  301.     register point2d *clampIn;
  302.     int color;
  303.     Object valId, showId;
  304. {
  305.     register valval *aValuator;
  306.  
  307.     if ((aValuator = (valval *)clone(&valValTemplate)) == NULL)
  308.     return list;
  309.     
  310.     aValuator->base.next = list;
  311.     aValuator->base.kids = NULL;
  312.     aValuator->base.dad  = dad;
  313.     aValuator->base.area = *ScrArea;
  314.     aValuator->base.painter = valId;
  315.  
  316.     aValuator->flags   = f;
  317.     setClamp(&aValuator->clamp, ScrArea, clampIn);
  318.     aValuator->world.orig.x = 0;
  319.     aValuator->world.orig.y = 0;
  320.     aValuator->world.extent.x = 0;
  321.     aValuator->world.extent.y = MAXVAL;
  322.     aValuator->display = showId;
  323.  
  324.     return (panel *)aValuator;
  325. }
  326.  
  327. setClamp(clampRect, rawRect, inset)
  328.     register rectangle *clampRect, *rawRect;
  329.     register point2d *inset;
  330. {
  331.     clampRect->orig.x = inset->x;
  332.     clampRect->orig.y = inset->y;
  333.     clampRect->extent.x = rawRect->extent.x - (2 * inset->x);
  334.     clampRect->extent.y = rawRect->extent.y - (2 * inset->y);
  335. }
  336.  
  337. #define interp(a,b,c,d) (((float)(a)/(float)(b)*(float)(c))+(float)(d))
  338.  
  339.     /*
  340.      *  draw a valuator's tracker at its current position
  341.      */
  342. drawVal(v)
  343.     register valuator *v;
  344. {
  345.     point2df curP;
  346.  
  347.     if (v->tracker) {
  348.     if ((v->world.extent.x != 0) && v->xVal)
  349.          curP.x = interp(*(v->xVal) - v->world.orig.x, v->world.extent.x,
  350.                       v->clamp.extent.x, v->clamp.orig.x);
  351.     else curP.x = ((float)v->clamp.extent.x/2.0) + (float)v->clamp.orig.x;
  352.  
  353.     if ((v->world.extent.y != 0) && v->yVal)
  354.          curP.y = interp(*(v->yVal) - v->world.orig.y, v->world.extent.y,
  355.                       v->clamp.extent.y, v->clamp.orig.y);
  356.     else curP.y = ((float)v->clamp.extent.y/2.0) + (float)v->clamp.orig.y;
  357.  
  358.     translate(curP.x, curP.y, 0.0);
  359.     callobj(v->tracker);
  360.     }
  361. }
  362.  
  363.  
  364.     /*
  365.      *  draw a floating point valuator's tracker at its current position
  366.      */
  367. drawValf(v)
  368.     register valuatorf *v;
  369. {
  370.     point2df curP;
  371.  
  372.     if (v->tracker) {
  373.     if ((v->world.extent.x != 0) && v->xVal)
  374.          curP.x = interp(*(v->xVal) - v->world.orig.x, v->world.extent.x,
  375.                       v->clamp.extent.x, v->clamp.orig.x);
  376.     else curP.x = ((float)v->clamp.extent.x/2.0) + (float)v->clamp.orig.x;
  377.  
  378.     if ((v->world.extent.y != 0) && v->yVal)
  379.          curP.y = interp(*(v->yVal) - v->world.orig.y, v->world.extent.y,
  380.                       v->clamp.extent.y, v->clamp.orig.y);
  381.     else curP.y = ((float)v->clamp.extent.y/2.0) + (float)v->clamp.orig.y;
  382.  
  383.     translate(curP.x, curP.y, 0.0);
  384.     callobj(v->tracker);
  385.     }
  386. }
  387.  
  388.     /*
  389.      *  draw a message valuator's tracker at its current position
  390.      */
  391. drawValMesg(v)
  392.     register valmesg *v;
  393. {
  394.     point2df curP;
  395.  
  396.     if (v->tracker) {
  397.     if (v->world.extent.x != 0)
  398.          curP.x = interp(v->val.x - v->world.orig.x, v->world.extent.x,
  399.                     v->clamp.extent.x, v->clamp.orig.x);
  400.     else curP.x = ((float)v->clamp.extent.x/2.0) + (float)v->clamp.orig.x;
  401.  
  402.     if (v->world.extent.y != 0)
  403.          curP.y = interp(v->val.y - v->world.orig.y, v->world.extent.y,
  404.                         v->clamp.extent.y, v->clamp.orig.y);
  405.     else curP.y = ((float)v->clamp.extent.y/2.0) + (float)v->clamp.orig.y;
  406.  
  407.     translate(curP.x, curP.y, 0.0);
  408.     callobj(v->tracker);
  409.     }
  410. }
  411.  
  412.  
  413.     /*
  414.      *  draw a floating point message valuator's tracker at its current position
  415.      */
  416. drawValMesgf(v)
  417.     register valmesgf *v;
  418. {
  419.     point2df curP;
  420.  
  421.     if (v->tracker) {
  422.     if (v->world.extent.x != 0.0)
  423.          curP.x = interp(v->val.x - v->world.orig.x, v->world.extent.x,
  424.                     v->clamp.extent.x, v->clamp.orig.x);
  425.     else curP.x = ((float)v->clamp.extent.x/2.0) + (float)v->clamp.orig.x;
  426.  
  427.     if (v->world.extent.y != 0.0)
  428.          curP.y = interp(v->val.y - v->world.orig.y, v->world.extent.y,
  429.                     v->clamp.extent.y, v->clamp.orig.y);
  430.     else curP.y = ((float)v->clamp.extent.y/2.0) + (float)v->clamp.orig.x;
  431.  
  432.     translate(curP.x, curP.y, 0.0);
  433.     callobj(v->tracker);
  434.     }
  435. }
  436.  
  437.     /*
  438.      *  draw a valuator's tracker at its current position
  439.      */
  440. drawColorVal(v)
  441.     register valval *v;
  442. {
  443.     RGBvalue r, g, b;
  444.     colorPanel *dad;
  445.  
  446.     if (dad = (colorPanel *)v->base.dad) {
  447.     /* map from hsv to rgb; */
  448.     /*   dad->hue, dad->satur, dad->value   */
  449.     /* mapcaller(dad->clientColor, r, g, b); */
  450.     callobj(v->display);
  451.     }
  452. }
  453.  
  454.  
  455.     /*
  456.      *  reset message valuator to orig
  457.      */
  458. resetValMesg(v, argtype, hit)
  459.     register valmesg *v;
  460.     long argtype;
  461.     hitstruct *hit;
  462. {
  463.     /* printf("resetValMesg: reset=%d\n", v->reset);  /* */
  464.  
  465.     if (v->reset == AUTORESET) {
  466.     v->val.x = 0;
  467.     v->val.y = 0;
  468.     }
  469. }
  470.  
  471.  
  472.     /*
  473.      *  reset floating point message valuator to orig
  474.      */
  475. resetValMesgf(v, argtype, hit)
  476.     register valmesgf *v;
  477.     long argtype;
  478.     hitstruct *hit;
  479. {
  480.     /* printf("resetValMesgf: reset=%d\n", v->reset);  /* */
  481.  
  482.     if (v->reset == AUTORESET) {
  483.     v->val.x = 0.0;
  484.     v->val.y = 0.0;
  485.     }
  486. }
  487.  
  488.  
  489.     /*
  490.      * process a selection on a valuator
  491.      */
  492. selectVal(self, argtype, hit)
  493.     register valuator *self;
  494.     long argtype;
  495.     register hitstruct *hit;
  496. {
  497.     if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
  498.     return;
  499.  
  500.     if (self->xVal) {
  501.     *(self->xVal) = (int)((float)(hit->x * self->world.extent.x) /
  502.                 (float)self->clamp.extent.x) + self->world.orig.x;
  503.     /* printf("selectVal: xVal=%d\n", *(self->xVal));
  504.     /* */
  505.     }
  506.     if (self->yVal) {
  507.     *(self->yVal) = (int)((float)(hit->y * self->world.extent.y) /
  508.                 (float)self->clamp.extent.y) + self->world.orig.y;
  509.     /* printf("selectVal: yVal=%d\n", *(self->yVal));
  510.     /* */
  511.     }
  512. }
  513.  
  514.  
  515.     /*
  516.      * process a selection on a floating point valuator
  517.      */
  518. selectValf(self, argtype, hit)
  519.     register valuatorf *self;
  520.     long argtype;
  521.     register hitstruct *hit;
  522. {
  523.     if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
  524.     return;
  525.  
  526.     if (self->xVal) {
  527.     *(self->xVal) = (((float)hit->x * self->world.extent.x) /
  528.               (float)self->clamp.extent.x)+self->world.orig.x;
  529.     /* printf("selectValf: xVal=%g\n", *(self->xVal));
  530.     /* */
  531.     }
  532.     if (self->yVal) {
  533.     *(self->yVal) = (((float)hit->y * self->world.extent.y) /
  534.               (float)self->clamp.extent.y)+self->world.orig.y;
  535.     /* printf("selectValf: yVal=%g\n", *(self->yVal));
  536.     /* */
  537.     }
  538. }
  539.  
  540.     /*
  541.      * process a selection on a delta valuator
  542.      */
  543. selectValDelta(self, argtype, hit)
  544.     register valdelta *self;
  545.     long argtype;
  546.     register hitstruct *hit;
  547. {
  548.     if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
  549.     return;
  550.  
  551.     if (self->xVal) {
  552.     *(self->xVal) += (int)((float)(hit->x * self->world.extent.x) /
  553.                 (float)self->clamp.extent.x) + self->world.orig.x;
  554.     clamp(self->xVal, self->limits.orig.x, self->limits.extent.x);
  555.     /* printf("selectValDelta: xVal=%d\n", *(self->xVal));
  556.     /* */
  557.     }
  558.     if (self->yVal) {
  559.     *(self->yVal) += (int)((float)(hit->y * self->world.extent.y) /
  560.                 (float)self->clamp.extent.y) + self->world.orig.y;
  561.     clamp(self->yVal, self->limits.orig.y, self->limits.extent.y);
  562.     /* printf("selectValDelta: yVal=%d\n", *(self->yVal));
  563.     /* */
  564.     }
  565. }
  566.  
  567.  
  568.     /*
  569.      * process a selection on a floating point delta valuator
  570.      */
  571. selectValDeltaf(self, argtype, hit)
  572.     register valdeltaf *self;
  573.     long argtype;
  574.     register hitstruct *hit;
  575. {
  576.     if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
  577.     return;
  578.  
  579.     if (self->xVal) {
  580.     *(self->xVal) += (((float)hit->x * self->world.extent.x) /
  581.               (float)self->clamp.extent.x)+self->world.orig.x;
  582.     clampf(self->xVal, self->limits.orig.x, self->limits.extent.x);
  583.     /* printf("selectValDeltaf: xVal=%g\n", *(self->xVal));
  584.     /* */
  585.     }
  586.     if (self->yVal) {
  587.     *(self->yVal) += (((float)hit->y * self->world.extent.y) /
  588.               (float)self->clamp.extent.y)+self->world.orig.y;
  589.     clampf(self->yVal, self->limits.orig.y, self->limits.extent.y);
  590.     /* printf("selectValDeltaf: yVal=%g\n", *(self->yVal));
  591.     /* */
  592.     }
  593. }
  594.  
  595.     /*
  596.      *  process a selection on a message valuator
  597.      */
  598. selectValMesg(self, argtype, hit)
  599.     register valmesg *self;
  600.     long argtype;
  601.     register hitstruct *hit;
  602. {
  603.     if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
  604.     return;
  605.  
  606.     self->val.x = (int)((float)(hit->x * self->world.extent.x) /
  607.             (float)self->clamp.extent.x) + self->world.orig.x;
  608.  
  609.     self->val.y = (int)((float)(hit->y * self->world.extent.y) /
  610.             (float)self->clamp.extent.y) + self->world.orig.y;
  611.  
  612.     /* printf("selectValMesg: val = %d, %d\n", self->val.x, self->val.y);
  613.     /* */
  614.  
  615.     Msg(self->receiver, self->selector, PTR, &self->val);
  616. }
  617.  
  618.     /*
  619.      *  process a selection on a message valuator
  620.      */
  621. selectValMesgf(self, argtype, hit)
  622.     register valmesgf *self;
  623.     long argtype;
  624.     register hitstruct *hit;
  625. {
  626.     if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
  627.     return;
  628.  
  629.     self->val.x = ((float)(hit->x * self->world.extent.x) /
  630.             (float)self->clamp.extent.x) + self->world.orig.x;
  631.  
  632.     self->val.y = ((float)(hit->y * self->world.extent.y) /
  633.             (float)self->clamp.extent.y) + self->world.orig.y;
  634.  
  635.     /* printf("selectValMesgf: val=%g,%g\n", self->val.x, self->val.y); /* */
  636.  
  637.     Msg(self->receiver, self->selector, PTR, &self->val);
  638. }
  639.  
  640.     /*
  641.      * process a selection on a valuator
  642.      */
  643. selectValHue(self, argtype, hit)
  644.     register valhue *self;
  645.     long argtype;
  646.     register hitstruct *hit;
  647. {
  648.     colorPanel *dad;
  649.  
  650.     if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
  651.     return;
  652.  
  653.     if (dad = (colorPanel *)self->base.dad) {
  654.     dad->hue = (int)((float)(hit->x * self->world.extent.x) /
  655.                 (float)self->clamp.extent.x) + self->world.orig.x;
  656.     printf("selectValHue: hue=%d\n", dad->hue);
  657.     /* */
  658.  
  659.     dad->satur = (int)((float)(hit->y * self->world.extent.y) /
  660.                 (float)self->clamp.extent.y) + self->world.orig.y;
  661.     printf("selectValHue: satur=%d\n", dad->satur);
  662.     /* */
  663.     }
  664. }
  665.  
  666.     /*
  667.      * process a selection on a valuator
  668.      */
  669. selectValVal(self, argtype, hit)
  670.     register valhue *self;
  671.     long argtype;
  672.     register hitstruct *hit;
  673. {
  674.     colorPanel *dad;
  675.  
  676.     if (boxclamp(&self->clamp, hit) && (self->flags & CLIPOUT))
  677.     return;
  678.  
  679.     if (dad = (colorPanel *)self->base.dad) {
  680.     dad->value = (int)((float)(hit->y * self->world.extent.y) /
  681.                 (float)self->clamp.extent.y) + self->world.orig.y;
  682.     printf("selectValHue: value=%d\n", dad->value);
  683.     /* */
  684.     }
  685. }
  686.  
  687.  
  688.     /*
  689.      *  clamp hit point so that it lies within limiting box
  690.      *  and translate it to lie relative to the limiting box area
  691.      */
  692. boxclamp(rectangle *bx, hitstruct *inpoint)
  693. {
  694.     register returnval = 0;
  695.  
  696.     if (inpoint->x < bx->orig.x) {
  697.     inpoint->x = bx->orig.x;
  698.     returnval = 1;
  699.     }
  700.     if (inpoint->x > bx->extent.x + bx->orig.x) {
  701.     inpoint->x = bx->extent.x + bx->orig.x;
  702.     returnval = 1;
  703.     }
  704.  
  705.     if (inpoint->y < bx->orig.y) {
  706.     inpoint->y = bx->orig.y;
  707.     returnval = 1;
  708.     }
  709.     if (inpoint->y > bx->extent.y + bx->orig.y) {
  710.     inpoint->y = bx->extent.y + bx->orig.y;
  711.     returnval = 1;
  712.     }
  713.  
  714.     inpoint->x -= bx->orig.x;
  715.     inpoint->y -= bx->orig.y;
  716.  
  717.     return returnval;
  718. }
  719.  
  720.     /*
  721.      *  clamp value pointed to so that it lies between lowlimit and hilimit
  722.      */
  723. clamp(val, lowlimit, hilimit)
  724.     int *val;
  725.     int lowlimit, hilimit;
  726. {
  727.     if (*val < lowlimit) *val = lowlimit;
  728.     if (*val > hilimit)  *val = hilimit;
  729. }
  730.  
  731.     /*
  732.      *  clamp floating point value so that it lies between lowlimit and hilimit
  733.      */
  734. clampf(val, lowlimit, hilimit)
  735.     Coord *val;
  736.     Coord lowlimit, hilimit;
  737. {
  738.     if (*val < lowlimit) *val = lowlimit;
  739.     if (*val > hilimit)  *val = hilimit;
  740. }
  741.